package cn.com.ghy.android.service;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.ghy.android.bean.CustomerInfoBean;
import cn.com.ghy.android.bean.CustomerInfoBeanParser;
import cn.com.ghy.android.bean.LoginInfoBean;
import cn.com.ghy.android.bean.MyWayBean;
import cn.com.ghy.android.bean.MyWayBeanParser;
import cn.com.ghy.android.util.CommonStatic;
import cn.com.ghy.android.util.CommonUtil;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:我的路线服务器
 * @author wuz  @date 2011-5-23 14:19:35
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class LineOpeService {
	private String url = CommonStatic.URL_HEAD + "LineOpe_Ar.asmx";
	private String methodName = "";
	private Map<String, String> params = null;
	
	private static final String USERID = "userid";
	private static final String STATE = "state";
	private static final String WAYID = "wayid";
	
	public List<MyWayBean> LineList(LoginInfoBean loginInfo) throws Exception {
		methodName = "LineList";
		params = new HashMap<String, String>();
		params.put(USERID, loginInfo.getPernr());
		params.put(STATE, "Y");
		String result = HttpService.callWS(url, methodName, params);
		byte[] buffer = org.kobjects.base64.Base64.decode(result);
		byte[] info = CommonUtil.decompressByteArray(buffer);
		InputStream in = new ByteArrayInputStream(info);
		List<MyWayBean> list = MyWayBeanParser.parseXML(in);
		in.close();
		CommonUtil.checkListNotNull(list);
		return list;
	}
	
	public List<CustomerInfoBean> LineDetail(LoginInfoBean loginInfo, String wayid) throws Exception {
		methodName = "LineDetail";
		params = new HashMap<String, String>();
		params.put(USERID, loginInfo.getPernr());
		params.put(WAYID, wayid);
		
		String result = HttpService.callWS(url, methodName, params);
		byte[] buffer = org.kobjects.base64.Base64.decode(result);
		byte[] info = CommonUtil.decompressByteArray(buffer);
		InputStream in = new ByteArrayInputStream(info);
		List<CustomerInfoBean> list = CustomerInfoBeanParser.parseXML(in);
		in.close();
		return list;
	}
}
